<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String CONT_PATH = request.getContextPath();
	request.setAttribute("CONT_PATH", CONT_PATH);
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	request.setAttribute("basePath", basePath);
%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="../../common/common.jspf"%>
<%-- <script type="text/javascript" src="${ctx}/js/goods/goodsClass/addGoodsClass.js"></script>
 --%>
<script type="text/javascript">

$(function(){
	var url = rootPath + '/goodsClass/initTree';
	var data = CommnUtil.ajax(url, null,"json");
	if (data != null) {
		var h = "<option value='0'>------顶级目录------</option>";
		for ( var i = 0; i < data.length; i++) {
			h+="<option value='" + data[i].id + "'>"+ data[i].name + "</option>";
		}
		$("#parentId").html(h);
	} else {
		layer.msg("获取菜单信息错误，请联系管理员！");
	}
	// 异步加载所有菜单列表
	$("#formSubmit").validate({
		submitHandler : function(form) {// 必须写在验证前面，否则无法ajax提交
			ly.ajaxSubmit(form,{//验证新增是否成功
				type : "post",
				//dataType : "json",
				success : function(data, status) {
					if (data == "success") {
						parent.layer.msg("操作成功！");
						prentClose();
			     		/* parent.grid.loadData();
						parent.layer.close(parent.pageii);
						return false; */
					} else {
						layer.msg("数据操作失败！");
						layer.alert('添加失败！', 3);
					}
				}
			});
		},
		rules : {
			"goodsClassMap.name" : {
				required : true,
				remote : { // 异步验证是否存在
					type : "POST",
					url : '${ctx}/goodsClass/isClassNameExist',
					data : {
						name : function() {
							return $("#name").val();
						}
					}
				} 
			},
			
			"goodsClassMap.parentId" : {
				required : true
			},
			"goodsClassMap.code" : {
				required : true
			}
		},
		messages : {
			"goodsClassMap.name" : {
				required : "商品分类名称不能为空！",
				remote : "该分类名称已经存在"
			},
			"goodsClassMap.parentId" : {
				required : "商品上级分类不能为空！"
			},
			"goodsClassMap.code" : {
				required : "商品分类编码不能为空！"
			}
		},
		errorPlacement : function(error, element) {// 自定义提示错误位置
			$(".l_err").css('display', 'block');
			// element.css('border','3px solid #FFCCCC');
			$(".l_err").html(error.html());
		},
		success : function(label) {// 验证通过后
			$(".l_err").css('display', 'none');
		}
	});


	
	//$(window.frames["iconFrame"].document).find("input[@type='radio']").attr("checked","true");

	/*  $('#iconFrame', parent.document).$(":radio").click(function(){
	 		alert("233")
		   alert("您是..." + $(this).val());
		   var icon = $(this).val();
		   $("#icon").val(icon);
	 }); */

});

	//定义图标方法，供子窗口调用
	function getIcon(val){
		$("#icon").val(val);
		//alert("调用成功！！！！")
	}

</script>


<style type="text/css">
#but button {
	margin-bottom: 5px;
	margin-right: 5px;
}
.col-sm-3 {
	width: 23%;
	float: left;
}

.col-sm-9 {
	width: 77%;
	float: left;
}

label[class^="btn btn-default"] {
	margin-top: -4px;
}
</style>
</head>
<body>
	<div class="l_err" style="width: 100%; margin-top: 2px;"></div>
	<form id="formSubmit" name="form" class="form-horizontal" method="post"
		action="${pageContext.request.contextPath}/goodsClass/subAddGoodsClass">
		<section class="panel panel-default">
			<div class="panel-body">
				<div class="form-group">
					<label class="col-sm-3 control-label">商品分类名称：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control checkacc"
							placeholder="请输入商品分类名称" name="goodsClassMap.name" id="name">
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">分类编码：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control checkacc"
							placeholder="请输入商品分类编码" name="goodsClassMap.code" id="code">
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">商品上级分类：</label>
					<div class="col-sm-9">
						<select id="parentId" name="goodsClassMap.parentId" class="form-control m-b"
							tabindex="-1">
						</select>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">排序编号：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control checkacc"
							placeholder="请输入分类排序号" name="goodsClassMap.sortNumber" id="sortNumber">
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-3 control-label">是否子节点：</label>
					<div class="col-sm-9">
						<select id="isEndNode" name="goodsClassMap.isEndNode" class="form-control m-b"
							tabindex="-1">
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</div>
				</div>
				
			 <div class="form-group">
					<label class="col-sm-3 control-label">分类图标：</label>
			 	<div class="col-sm-9">
			 		<input type="text" class="form-control checkacc"
							placeholder="请选择图标" name="goodsClassMap.icon" readonly="readonly" id="icon">
			 		<iframe id="iconFrame" name="iconFrame" src="${basePath}icon/icon.jsp" style="width: 100%;border:0px #69f solid;height: 122px;" frameborder="0" scrolling="auto"></iframe> 
				</div>
			</div>
			</div>
			<footer class="panel-footer text-right bg-light lter">
			<button type="submit" class="btn btn-success btn-s-xs">提交</button>
			</footer> 
		</section>
	</form>
</body>
</html>